package com.trust.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trust.agri.util.BeanUtil;
import com.trust.entity.InventoryMaterial;
import com.trust.entity.VO.DictionaryVO;
import com.trust.entity.VO.InventoryMaterialDropDownVO;
import com.trust.mapper.InventoryMaterialMapper;
import com.trust.service.InventoryMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class InventoryMaterialServiceImpl extends ServiceImpl<InventoryMaterialMapper, InventoryMaterial> implements InventoryMaterialService {

    @Override
    public List<InventoryMaterial> getByInCode(String code) {
        LambdaQueryWrapper<InventoryMaterial> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryMaterial::getInCode, code);
        return this.list(wrapper);
    }

    @Override
    public List<InventoryMaterialDropDownVO> dropDownList(Integer type) {
        LambdaQueryWrapper<InventoryMaterial> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(null != type, InventoryMaterial::getMaterialType, type);
        wrapper.orderByDesc(InventoryMaterial::getId);
        return BeanUtil.sourceList2targetList(this.list(wrapper), InventoryMaterialDropDownVO.class);
    }

    @Override
    public List<DictionaryVO> storehouseBreed(Integer type) {
        LambdaQueryWrapper<InventoryMaterial> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(InventoryMaterial::getType, type);
        List<InventoryMaterial> list = this.list(wrapper);
        ArrayList<DictionaryVO> vos = new ArrayList<>();
        for (InventoryMaterial material : list) {
            DictionaryVO vo = new DictionaryVO();
            vo.setId(material.getId());
            vo.setName(material.getCode());
            vos.add(vo);
        }
        return vos;
    }
}
